<script>
	function reloadPage(){
		location.reload();
	}
	function addData(){
	
	}
	function editRow(id){
		
	}
	function deleteRow(id){
		if (confirm("Delete data ?")){			
			window.parent.showLoader();			
			var data = $("#tblTahunAjaran").jqGrid("getRowData",id);
			var editUrl = $("#tblTahunAjaran").jqGrid("getGridParam","editUrl");
			
			$.ajax({	
				url : editUrl,
				type:"GET",
				async:false,
				data: {oper: "del",id:data.id},
				success: function(data) {
					alert("success!");
				},
				complete:function(){
					window.parent.hideLoader();
					alert("complete!");
				}
			});
			
			$("#tblTahunAjaran").jqGrid("delRowData",id);
			
		}
	}
	
	
	$(function(){
		var numberTemplate = {formatter: 'number', align: 'right', sorttype: 'number'};	 
		$("#tblTahunAjaran").jqGrid({
			url:'index.php?r=akMaster_TahunAjaran/detailList',
			editUrl:'index.php?r=akMaster_TahunAjaran/edit',
			datatype: 'json',
			loadOnce:true,
			mtype:"GET",
			autowidth:true,
			height:"100%",
			colNames: ['id','Tahun Ajaran', 'Mulai',  'Akhir', 'Keterangan', 'Status','Action'],
			colModel: [
				{name: 'id', index: 'id', hidden:true},
				{name: 'name', index: 'name', width: 40},
				{name: 'start_date', index: 'start_date', width: 50, align: 'center', sorttype: 'date',
					formatter: 'date', formatoptions: {newformat: 'd-M-Y'}, datefmt: 'd-M-Y'},
				{name: 'end_date', index: 'end_date', width: 50, align: 'center', sorttype: 'date',
					formatter: 'date', formatoptions: {newformat: 'd-M-Y'}, datefmt: 'd-M-Y'},
				{name: 'description', index: 'description'},
				{name: 'is_active', index: 'is_active', width: 30, align: 'center', formatter: 'checkbox'},
				{name: 'act', index: 'act', width: 40, align: 'center'},
				
			],
			gridview: true,
			rownumbers: false,
			rowNum: 10,
			rowList: [5, 10, 15],
			pager: '#navTblTahunAjaran',
			sortname: 'orderdate',
			viewrecords: true,
			sortorder: 'desc',
			caption: 'Tahun Ajaran',
			jsonReader : { 
				root:"model",
				repeatitems: false			
			},
			loadComplete:function(data){},
			gridComplete: function(){ 
				var ids = jQuery("#tblTahunAjaran").getDataIDs(); 
				for(var i=0;i<ids.length;i++){ 
					var cl = ids[i]; 
					//btnEdit = "<input style='height:22px;width:20px;' type='button' value='E' onclick=jQuery('#rowed2').editRow("+cl+"); ></ids>"; 
					//btnDelete = "<input style='height:20px;width:20px;' type='button' value='S' onclick=jQuery('#rowed2').saveRow("+cl+"); />"; 
					btnEdit = "<img title='edit' class='imgBtn' style='height:20px;width:20px;' src='images/action/Actions-Edit-icon.png' onclick='editRow(" + cl + ")' />"; 
					btnDelete = "<img title='delete' class='imgBtn' style='margin-left:5px;height:20px;width:20px;' src='images/action/Actions-Delete-icon.png' onclick='deleteRow(" + cl + ")' />"; 
					
					jQuery("#tblTahunAjaran").setRowData(ids[i],{act:btnEdit+btnDelete}) 
				} 
			}
		});
	});
</script>
<div style="">
	<div style="float:left">
		<input type="text" id="srcTblTahunAjaran" size=20 />
	</div>
	<div style="float:rigth">
	<?php 
		$this->widget('application.components.widgets.ActionBar', 
			array("menuAlign" => "right", 
				'items' => array(
					array(
						'id' => "btnRefresh",
						'title' => "Refresh",
						'icon' => "images/action/Action-Refresh-icon.png",
						'callback'=>"reloadPage"
					),					
					array(
						'id' => "btnAdd",
						'title' => "New",
						'icon' => "images/action/Actions-document-new-icon.png",
						'callback'=>"test"
					),									
				)
			)
		);
	?>
	</div>	
	<div style="clear:both"></div>
	<table id="tblTahunAjaran"><tr></tr></table>
	<div id="navTblTahunAjaran"></div>
</div>